﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.Windows.Forms;



namespace MINERP.COM
{
    /// <summary>
    /// 退出登陆后的操作类
    /// </summary>
    public class Logoff
    {

        private static readonly int UM_RESETPRINTER = 0x402;

        [DllImport("user32.dll",EntryPoint="SendMessage")] 

        private static extern int SendMessage( 
                                                IntPtr hWnd,   // handle to destination window 
                                                int Msg,    // message 
                                                int wParam, // first message parameter 
                                                int lParam // second message parameter 
                                                ); 


        [DllImport("user32.dll")]
        public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
        [DllImport("user32.dll")]
        public static extern bool SetWindowPos(int hWnd, int hWndlnsertAfter, int X, int Y, int cx, int cy, uint Flags);

        public static void ShowMainFrm()
        {
            int handle = (int)FindWindow(null, "角色选择");
            if (handle > 0)
            {
                SetWindowPos(handle, -2, 0, 0, Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height, 0x40);
            }
        }
        public static void ShowMainFrm(string formName)
        {
            int handle = (int)FindWindow(null, formName);
            if (handle > 0)
            {
                SetWindowPos(handle, -2, 0, 0, Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height, 0x40);
            }
        }
        /// <summary>
        /// 复位打印机
        /// </summary>
        /// <param name="frm"></param>
        public static void ResetPrinter()
        {
            foreach (Form frm in  Application.OpenForms)
            {
                if (frm.Name == "FrmMain")
                {
                    int ret = SendMessage(frm.Handle, UM_RESETPRINTER, 0, 0);
                }
            } 

        }
    }
}
